﻿Public Class Rvendedor

    Dim objdatVendedor As New EVOLTA.Promocion.Dl.Dal.Dvendedor

    Public Shared Function SeleccionarTodo(ByVal descEmpresa As String, ByVal DisplaySelect As Boolean) As List(Of Evendedor)
        Dim vendedors As List(Of Evendedor) = Nothing

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                vendedors = Dvendedor.SeleccionarTodo(descEmpresa)
                If vendedors Is Nothing Then vendedors = New List(Of Evendedor)
                If DisplaySelect Then vendedors.Insert(0, New Evendedor("00", "-- SELECCIONAR --"))
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return vendedors
    End Function
    'Public Shared Function SeleccionarTodoXML(ByVal descEmpresa As String, ByVal DisplaySelect As Boolean) As System.Xml.XmlReader
    '    Dim options As New TransactionOptions
    '    options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
    '    options.Timeout = New TimeSpan(0, 2, 0)

    '    Using scope As New TransactionScope(TransactionScopeOption.Required, options)
    '        Try
    '            Return Dvendedor.SeleccionarTodoXML(descEmpresa)
    '            scope.Complete()
    '        Catch ex As Exception
    '            Throw
    '        End Try
    '    End Using
    'End Function
    Public Shared Function SeleccionarXEstado(ByVal descEmpresa As String, ByVal DisplaySelect As Boolean) As List(Of Evendedor)
        Dim vendedors As List(Of Evendedor) = Nothing

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                vendedors = Dvendedor.SeleccionarXEstado(descEmpresa)
                If vendedors Is Nothing Then vendedors = New List(Of Evendedor)
                If DisplaySelect Then vendedors.Insert(0, New Evendedor("00", "-- SELECCIONAR --"))
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return vendedors
    End Function
    Public Shared Function SeleccionarXUsuario(ByVal descEmpresa As String, ByVal idUsuario As Integer) As Evendedor
        Dim vendedor As Evendedor

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                vendedor = Dvendedor.SeleccionarXUsuario(descEmpresa, idUsuario)
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return vendedor
    End Function
    Public Shared Function Añadir(ByVal descEmpresa As String, ByVal pVendedor As Evendedor) As Boolean
        Dim resultado As Boolean = False

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                resultado = Dvendedor.Añadir(descEmpresa, pVendedor)
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return resultado
    End Function
    Public Shared Function Editar(ByVal descEmpresa As String, ByVal pVendedor As Evendedor) As Boolean
        Dim resultado As Boolean = False

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                resultado = Dvendedor.Editar(descEmpresa, pVendedor)
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return resultado
    End Function
    Public Shared Function Eliminar(ByVal descEmpresa As String, ByVal pVendedor As Evendedor) As Boolean
        Dim resultado As Boolean = False

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                resultado = Dvendedor.Eliminar(descEmpresa, pVendedor)
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return resultado
    End Function

    Public Function negCargar_vendedores(ByVal strEmpresa As String) As DataTable
        Return objdatVendedor.datCargar_vendedores(strEmpresa)
    End Function

End Class
